//
//  AppDelegate.m
//  didacar
//
//  Created by 度周末网络-王腾 on 15/11/20.
//  Copyright © 2015年 dzmmac. All rights reserved.
//

#import "AppDelegate.h"
#import "GpsManager.h"
#import <MAMapKit/MAMapKit.h>
#import "UmengTrackObject.h"
#import "APService.h"
#import "UMSocialSnsService.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.cityViewModel = [[CityViewModel alloc ] init];
    [self.cityViewModel loadData:^(NSInteger resultType, id data, NSString *errorMsg) {
        if (resultType == 1) {
            // 定位
            [[GpsManager shareManager] startGPS];
        }
    }];
    
    
    // 友盟分享配置
    [[UmengTrackObject sharedManager] umengShareConfig];
    
    [self GDMapConfig];
    
    [self configJPush:launchOptions];
    return YES;
}

/**
 *  配置JPush
 *
 *  @param launchOptions 启动时的参数
 */
-(void)configJPush:(NSDictionary *)launchOptions
{
    [APService setupWithOption:launchOptions];
    [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                   UIRemoteNotificationTypeSound |
                                                   UIRemoteNotificationTypeAlert)
                                       categories:nil];
    
    [APService resetBadge];
    
}

// 高德地图
-(void)GDMapConfig
{

//    fa516211dd0992d518a2dd4162fce7b7
//    cf235d285d058d4336262bcdd99db3f8
    // 高德地图初始化
    [MAMapServices sharedServices].apiKey = @"cf235d285d058d4336262bcdd99db3f8";
    
}

- (void)applicationWillResignActive:(UIApplication *)application {
  
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
   
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    [APService registerDeviceToken:deviceToken];
    /*
     NSString *pushToken = [[[[deviceToken description]
     stringByReplacingOccurrencesOfString:@"<" withString:@""]
     stringByReplacingOccurrencesOfString:@">" withString:@""]
     stringByReplacingOccurrencesOfString:@" " withString:@""];
     */
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    [application setApplicationIconBadgeNumber:0];
    [UMSocialSnsService  applicationDidBecomeActive];
}

/**
 这里处理新浪微博SSO授权之后跳转回来，和微信分享完成之后跳转回来
 */
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    return  [UMSocialSnsService handleOpenURL:url wxApiDelegate:nil];
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
   
}

- (void)applicationWillTerminate:(UIApplication *)application {
   
}

@end
